n=eval(input())
arr=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
answer=['1','0','X','9','8','7','6','5','4','3','2']
flag=0
for i in range(1, n+1):
    s=input()
    sum=0
    stand=0
    for i in range(len(s)-1):
        if s[i]>='A' and s[i]<='Z' :
            print(s)
            flag=1
            stand=1
            break
    if stand:
        continue
    for i in range(len(s)-1):
        if s[i]>='0' and s[i]<='9':
            sum+=int(s[i])*arr[i]
        sum%=11
    if answer[sum]!=s[len(s)-1]:
        print(s)
        flag=1
        
if not flag:
    print("All passed")